package main

import (
	"fmt"
	"os"
	"os/signal"
	"syscall"

	"github.com/yjp211/web"

	"mutu/misc/conf"
	"mutu/misc/log"

	_ "mutu/misc/cstore"
	_ "mutu/misc/redis"

	_ "mutu/models"
	_ "mutu/routers"
)

var (
	QuitSignal chan os.Signal
)

func init() {
	QuitSignal = make(chan os.Signal, 1)
	signal.Notify(QuitSignal, os.Interrupt)
	signal.Notify(QuitSignal, syscall.SIGTERM)

	go cleanup()
}

func cleanup() {
	<-QuitSignal
	log.Log.Info("----------end---------")
	os.Exit(1)
}

func main() {
	log.Log.Info("----------begin---------")

	_listen := fmt.Sprintf("0.0.0.0:%d", conf.GetInt("ListenPort", 8080))

	web.Config.StaticPerfix = "/static/"
	web.Config.StaticDir = "./static/"
	web.Config.TemplatesDir = "./templates/"
	web.Config.CookieSecret = "7C19QRmwf3mHZ9CPAaPQ0hsWeufKd"
	web.Run(_listen)
}
